Fix TwitterStreamAgent specs and mock puts calls

Dominik Sander 8 anni fa
parent
commit
c52a508d4d
2 ha cambiato i file con 12 aggiunte e 3 eliminazioni
  1. 1 0
      spec/concerns/long_runnable_spec.rb
  2. 11 3
      spec/models/agents/twitter_stream_agent_spec.rb

+ 1 - 0
spec/concerns/long_runnable_spec.rb

@@ -118,6 +118,7 @@ describe LongRunnable do
118 118
         mock(@worker).stop!
119 119
         mock(@worker).setup!(@worker.scheduler, @worker.mutex)
120 120
         mock(@worker).run!
121
+        mock(@worker).puts(anything) { |text| expect(text).to match(/Restarting/) }
121 122
         @worker.restart!
122 123
       end
123 124
     end

+ 11 - 3
spec/models/agents/twitter_stream_agent_spec.rb

@@ -169,20 +169,23 @@ describe Agents::TwitterStreamAgent do
169 169
       @config = {agent: @agent, config: {filter_to_agent_map: {'agent' => [@mock_agent]}}}
170 170
       @worker = Agents::TwitterStreamAgent::Worker.new(@config)
171 171
       @worker.instance_variable_set(:@recent_tweets, [])
172
-      mock(@worker).schedule_in(Agents::TwitterStreamAgent::Worker::RELOAD_TIMEOUT)
172
+      #mock(@worker).schedule_in(Agents::TwitterStreamAgent::Worker::RELOAD_TIMEOUT)
173 173
       @worker.setup!(nil, Mutex.new)
174 174
     end
175 175
 
176 176
     context "#run" do
177
-      it "starts the stream" do
177
+      before(:each) do
178 178
         mock(EventMachine).run.yields
179
+        mock(EventMachine).add_periodic_timer(3600)
180
+      end
181
+
182
+      it "starts the stream" do
179 183
         mock(@worker).stream!(['agent'], @agent)
180 184
         mock(Thread).stop
181 185
         @worker.run
182 186
       end
183 187
 
184 188
       it "yields received tweets" do
185
-        mock(EventMachine).run.yields
186 189
         mock(@worker).stream!(['agent'], @agent).yields('status' => 'hello')
187 190
         mock(@worker).handle_status('status' => 'hello')
188 191
         mock(Thread).stop
@@ -222,6 +225,9 @@ describe Agents::TwitterStreamAgent do
222 225
         it "logs error messages" do
223 226
           stub_without(:on_error).on_error.yields('woups')
224 227
           mock(STDERR).puts(anything) { |text| expect(text).to match(/woups/) }
228
+          mock(STDERR).puts(anything) { |text| expect(text).to match(/Sleeping/) }
229
+          mock(@worker).sleep(15)
230
+          mock(@worker).restart!
225 231
           @worker.send(:stream!, ['agent'], @agent)
226 232
         end
227 233
 
@@ -257,6 +263,7 @@ describe Agents::TwitterStreamAgent do
257 263
 
258 264
       it "deduplicates tweets" do
259 265
         @worker.send(:handle_status, {'text' => 'dup', 'id_str' => '1'})
266
+        mock(@worker).puts(anything) { |text| expect(text).to match(/Skipping/) }
260 267
         @worker.send(:handle_status, {'text' => 'dup', 'id_str' => '1'})
261 268
         expect(@worker.instance_variable_get(:'@recent_tweets').select { |str| str == '1' }.length).to eq 1
262 269
       end
@@ -264,6 +271,7 @@ describe Agents::TwitterStreamAgent do
264 271
       it "calls the agent to process the tweet" do
265 272
         mock(@mock_agent).name { 'mock' }
266 273
         mock(@mock_agent).process_tweet('agent', {'text' => 'agent'})
274
+        mock(@worker).puts(anything) { |text| expect(text).to match(/received/) }
267 275
         @worker.send(:handle_status, {'text' => 'agent', 'id_str' => '123'})
268 276
         expect(@worker.instance_variable_get(:'@recent_tweets')).to include('123')
269 277
       end